package com.onepice.mlp.core.serviceImpl;

import com.onepice.mlp.core.service.SyslogService;
import com.onepice.mlp.data.dao.SyslogDao;
import com.onepice.mlp.data.entity.Syslog;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/07/11 23:25:03
 */
@Service
@AllArgsConstructor
@Transactional
public class SyslogServiceImpl implements SyslogService {
    private SyslogDao syslogDao;

    @Override
    public List<Syslog> getAll() {
        return syslogDao.findAll();
    }

    @Override
    public Syslog getById(Integer id) {
        Optional<Syslog> syslog = syslogDao.findById(id);
        return syslog.get();
    }

    @Override
    public void insert(Syslog syslog) {
        syslog.setCreateTime(new Date());
        syslogDao.save(syslog);
    }

    @Override
    public void update(Syslog syslog) {
        syslogDao.save(syslog);
    }

    @Override
    public void deleteById(Integer id) {
        syslogDao.deleteById(id);
    }
}
